//   顶部展示栏配置
//   路由点击全局处理
export default class route {
	constructor() {
		const Vue_ = arguments[0].prototype;
		Vue_.$toRoutePath = this.toRoutePath;
		Vue_.$filterParam = this.filterParam;
		Vue_.$blackRoute = this.blackRoute;
		Vue_.$setRouteTitle = this.setRouteTitle;
	}

	/**
	 *
	 *   @param {object} pathObj
	 *   pathObj.edit    是否修改顶部栏    true  or  false
	 *   pathObj.path    跳转路由地址
	 *
	 *
	 */
	toRoutePath(routeInfo) {
		switch (typeof routeInfo) {
			case "object":
				this.$router.push({path: routeInfo.path, query: routeInfo.query || {}, params: routeInfo.params || {}});
				break;
			case "string":
				this.$router.push({path: routeInfo});
				break;
			case "undefined":
				this.$message.error('请设置正确的跳转路由');
		}
	}

	/**
	 * 过滤空字符串字段
	 */
	filterParam(param) {
		let post_data = {};
		for (let val in param) {
			if (param[val] != '') {
				post_data[val] = param[val];
			}
		}
		return post_data;
	}

	/**
	 *
	 *  撤回-返回上一个页面
	 *
	 */
	blackRoute(obj) {
		console.log(obj);
		this.$router.push({
			path: obj.path,
			name: obj.name,
			params: {
				...obj.params,
				path: obj.path
			},
			query:{
				...obj.query
			}
		});
	}

	/**
	 * 设置
	 */
	setRouteTitle(path, title) {
		let navList = [...this.$store.state.ysnavList];
		navList = navList.filter(nav => {
			if (nav.path == path) {
				nav.title = title;
			}
			return nav;
		});
		this.$store.commit("navListChange", navList);
	}
}
